package com.bingfor.easycablelink.product;

import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

import com.bingfor.easycablelink.R;
import com.bingfor.easycablelink.base.BaseActivity;
import com.bingfor.easycablelink.base.BaseFragment;
import com.bingfor.easycablelink.base.ViewPagerFragmentAdapter;
import com.bingfor.easycablelink.base.WebViewActivity;
import com.bingfor.easycablelink.databinding.ActivityProductQuotationBinding;
import com.bingfor.easycablelink.home.Fragment.logistical.LogisticalPage;
import com.bingfor.easycablelink.my.ShoppingCartActivity;
import com.bingfor.easycablelink.utils.ActivityUtil;
import com.bingfor.easycablelink.widgets.BannerLayout;
import com.bingfor.easycablelink.widgets.ServiceDialog;

import java.util.ArrayList;
import java.util.List;

/**
*产品报价
*@author LY
*@time 2017/5/31 19:46
* des:create file and achieve model
*/

public class ProductQuotationActivity extends BaseActivity {

    ActivityProductQuotationBinding binding;
    List<String> urls = new ArrayList<>();
    TabLayout mTabLayout;
    List<String> titleList = new ArrayList<>();
    List<BaseFragment> fragmentList = new ArrayList<>();
    ViewPagerFragmentAdapter adapter ;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityProductQuotationBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        initToolbar();
    }

    @Override
    public void initViews() {
        urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1496241699271&di=433d0fb9d1353b184e0fb5e8e349422b&imgtype=0&src=http%3A%2F%2Fp3.gexing.com%2Fshaitu%2F20130103%2F1843%2F50e560e3ceed3.jpg");
        urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1496241699270&di=71d49e99da6f4e27d1891f1d82d15c68&imgtype=0&src=http%3A%2F%2Fv1.qzone.cc%2Fskin%2F201510%2F12%2F19%2F02%2F561b935de45a9240.jpg%2521600x600.jpg");
        urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1496241699269&di=0d2580b8082ba6bc01f1735b57a5a16e&imgtype=0&src=http%3A%2F%2Ftupian.enterdesk.com%2F2015%2Flcx%2F1%2F26%2F5%2F1.jpg");

        binding.mBannerLayout.setViewUrls(urls);
        binding.mBannerLayout.setOnBannerItemClickListener(new BannerLayout.OnBannerItemClickListener() {
            @Override
            public void onItemClick(int position){
                Bundle bundle = new Bundle();
                bundle.putString("url","https://www.baidu.com");
                bundle.putString("title","品牌详情");
                bundle.putString("flag","1");
                ActivityUtil.getAppManager().move2NextPage(WebViewActivity.class,bundle);
            }
        });

        mTabLayout = $(R.id.mTabLayout);
        ViewPager mViewPager = $(R.id.mViewPager);
        adapter = new ViewPagerFragmentAdapter(mContext.getSupportFragmentManager(), fragmentList, titleList);
        mViewPager.setAdapter(adapter);
        mViewPager.setOffscreenPageLimit(10);
        mTabLayout.setupWithViewPager(mViewPager);
        initData();
    }
    private void initData(){
        titleList.add("厂家标准");
        titleList.add("企业标准");
        titleList.add("国家标准");
//        titleList.add("钢架壁纸");
//
        fragmentList.add( QuotationPage.getInstance(0)) ;
        fragmentList.add( QuotationPage.getInstance(1));
//        fragmentList.add( LogisticalPage.getInstance(2));
        fragmentList.add( QuotationPage.getInstance(3));

        for (int i = 0; i <3; i++) {

            Bundle bundle = new Bundle();
            bundle.putSerializable("item",titleList.get(i));
            bundle.putInt("id",i);
            fragmentList.get(i).setArguments(bundle);
            titleList.add(i+"");
        }
        adapter.notifyDataSetChanged();
    }


    @Override
    public void initToolbar() {
        Toolbar toolbar = $(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        setTitle("产品报价");
        initViews();
    }

    @Override
    public void refresh() {

    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu_right_product_control, menu);

        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.menu_call:
                moveToNextPage(ServiceDialog.class);
                break;
            case R.id.menu_cat:
                moveToNextPage(ShoppingCartActivity.class);
                break;
        }
        return super.onOptionsItemSelected(item);
    }
}
